package com.xbfinal.myzhxy.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xbfinal.myzhxy.mapper.ClazzMapper;
import com.xbfinal.myzhxy.pojo.Clazz;

import com.xbfinal.myzhxy.service.ClazzSerivice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;

@Service("ClazzServiceImpl")
@Transactional
public class ClazzServiceImpl
        extends ServiceImpl<ClazzMapper, Clazz>
        implements ClazzSerivice  {
    @Override
    public IPage<Clazz> getBradeByOpr(Page<Clazz> page, Clazz clazz) {
        QueryWrapper<Clazz> queryWrapper=new QueryWrapper<>();
        //查询年级是否为空
        String GradeName = clazz.getGradeName();
        if(!(StringUtils.isEmpty(GradeName))){
            queryWrapper.like("grade_name",GradeName);
        }
        //查询班级名
        final String name = clazz.getName();
        if(!(StringUtils.isEmpty(name))){
            queryWrapper.like("name",name);
        }
        //降序排序根据id
        queryWrapper.orderByDesc("id");

        final Page<Clazz> page1 = baseMapper.selectPage(page, queryWrapper);
        //Page继承了IPage
        return page1;
    }
}
